def group_5(tree):
    dict_group_5 = {"是否吸烟": "", "开始吸烟时间": "", "戒断时间": "", "吸烟量": "", "是否饮酒": "", "饮酒类型": "", "饮酒量": "", "饮酒频率": "",
                    "戒酒日期": "", "是否锻炼": "", "锻炼情况": "", "每次锻炼时间": "", "锻炼类型": None, "饮食习惯": "", "饮食量(主食量)": "",
                    "睡眠时间": "", "睡眠情况": "", "其它习惯": ""}
    try:
        xiyan_t_f = tree.xpath('//input[@name="EHRDETAILS.smSmoking" and @checked="checked"]')[0]
        dict_group_5["是否吸烟"] = xiyan_t_f.xpath('following-sibling::span/label/text()')[0]
    except:
        dict_group_5["是否吸烟"] = None

    if dict_group_5["是否吸烟"] == "是":
        sm_start = tree.xpath('//input[@name="EHRDETAILS.smStart"]/@value')[0] if tree.xpath(
            '//input[@id="smStart"]/@value') else None
        dict_group_5["开始吸烟时间"] = sm_start
        dict_group_5["戒断时间"] = None
        try:
            sm_level = tree.xpath('//input[@name="EHRDETAILS.smAmount" and @checked="checked"]')[0]
            dict_group_5["吸烟量"] = sm_level.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["吸烟量"] = "无"

    elif dict_group_5["是否吸烟"] == "否":
        dict_group_5["开始吸烟时间"] = None
        dict_group_5["戒断时间"] = None
        dict_group_5["吸烟量"] = "无"
    elif dict_group_5["是否吸烟"] == "已戒":
        sm_start = tree.xpath('//input[@name="EHRDETAILS.smStart"]/@value')[0] if tree.xpath(
            '//input[@id="smStart"]/@value') else None
        dict_group_5["开始吸烟时间"] = sm_start
        sm_start = tree.xpath('//input[@name="EHRDETAILS.smEnd"]/@value')[0] if tree.xpath(
            '//input[@id="smStart"]/@value') else None
        dict_group_5["戒断时间"] = sm_start
        try:
            sm_level = tree.xpath('//input[@name="EHRDETAILS.smAmount" and @checked="checked"]')[0]
            dict_group_5["吸烟量"] = sm_level.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["吸烟量"] = "无"
    else:
        dict_group_5["是否吸烟"] = None
        dict_group_5["开始吸烟时间"] = None
        dict_group_5["戒断时间"] = None
        dict_group_5["吸烟量"] = "无"
    # 饮酒史
    try:
        xiyan_t_f = tree.xpath('//input[@name="EHRDETAILS.dkDrinking" and @checked="checked"]')[0]
        dict_group_5["是否饮酒"] = xiyan_t_f.xpath('following-sibling::span/label/text()')[0]
    except:
        dict_group_5["是否饮酒"] = None
    if dict_group_5["是否饮酒"] == "是":
        try:
            jiu_type = tree.xpath('//input[@name="EHRDETAILS.dkType" and @checked="checked"]')[0]
            dict_group_5["饮酒类型"] = jiu_type.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒类型"] = "无"
        try:
            jiu_level = tree.xpath('//input[@name="EHRDETAILS.dkAmount" and @checked="checked"]')[0]
            dict_group_5["饮酒量"] = jiu_level.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒量"] = "无"
        try:
            jiu_num = tree.xpath('//input[@name="EHRDETAILS.dkRate" and @checked="checked"]')[0]
            dict_group_5["饮酒频率"] = jiu_num.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒频率"] = "无"
        jiu_jie_date = tree.xpath('//input[@name="EHRDETAILS.dkEnd"]/@value')[0] if tree.xpath(
            '//input[@id="smStart"]/@value') else None
        if jiu_jie_date == "":
            dict_group_5["戒酒日期"] = None
        else:
            dict_group_5["戒酒日期"] = jiu_jie_date
    elif dict_group_5["是否饮酒"] == "否":
        try:
            jiu_type = tree.xpath('//input[@name="EHRDETAILS.dkType" and @checked="checked"]')[0]
            dict_group_5["饮酒类型"] = jiu_type.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒类型"] = "无"
        try:
            jiu_level = tree.xpath('//input[@name="EHRDETAILS.dkAmount" and @checked="checked"]')[0]
            dict_group_5["饮酒量"] = jiu_level.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒量"] = "无"
        try:
            jiu_num = tree.xpath('//input[@name="EHRDETAILS.dkRate" and @checked="checked"]')[0]
            dict_group_5["饮酒频率"] = jiu_num.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒频率"] = "无"
        jiu_jie_date = tree.xpath('//input[@name="EHRDETAILS.dkEnd"]/@value')[0] if tree.xpath(
            '//input[@id="smStart"]/@value') else None
        if jiu_jie_date == "":
            dict_group_5["戒酒日期"] = None
        else:
            dict_group_5["戒酒日期"] = jiu_jie_date
    elif dict_group_5["是否饮酒"] == "已戒":
        try:
            jiu_type = tree.xpath('//input[@name="EHRDETAILS.dkType" and @checked="checked"]')[0]
            dict_group_5["饮酒类型"] = jiu_type.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒类型"] = "无"
        try:
            jiu_level = tree.xpath('//input[@name="EHRDETAILS.dkAmount" and @checked="checked"]')[0]
            dict_group_5["饮酒量"] = jiu_level.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒量"] = "无"
        try:
            jiu_num = tree.xpath('//input[@name="EHRDETAILS.dkRate" and @checked="checked"]')[0]
            dict_group_5["饮酒频率"] = jiu_num.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒频率"] = "无"
        jiu_jie_date = tree.xpath('//input[@name="EHRDETAILS.dkEnd"]/@value')[0] if tree.xpath(
            '//input[@id="smStart"]/@value') else None
        if jiu_jie_date == "":
            dict_group_5["戒酒日期"] = None
        else:
            dict_group_5["戒酒日期"] = jiu_jie_date
    else:
        dict_group_5["是否饮酒"] = None
        try:
            jiu_type = tree.xpath('//input[@name="EHRDETAILS.dkType" and @checked="checked"]')[0]
            dict_group_5["饮酒类型"] = jiu_type.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒类型"] = "无"
        try:
            jiu_level = tree.xpath('//input[@name="EHRDETAILS.dkAmount" and @checked="checked"]')[0]
            dict_group_5["饮酒量"] = jiu_level.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒量"] = "无"
        try:
            jiu_num = tree.xpath('//input[@name="EHRDETAILS.dkRate" and @checked="checked"]')[0]
            dict_group_5["饮酒频率"] = jiu_num.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["饮酒频率"] = "无"
        jiu_jie_date = tree.xpath('//input[@name="EHRDETAILS.dkEnd"]/@value')[0] if tree.xpath(
            '//input[@id="smStart"]/@value') else None
        if jiu_jie_date == "":
            dict_group_5["戒酒日期"] = None
        else:
            dict_group_5["戒酒日期"] = jiu_jie_date




    # 体育锻炼
    try:
        sport_t_f = tree.xpath('//input[@name="EHRDETAILS.exExercise" and @checked="checked"]')[0]
        dict_group_5["是否锻炼"] = sport_t_f.xpath('following-sibling::span/label/text()')[0]
    except:
        dict_group_5["是否锻炼"] = None
    if dict_group_5["是否锻炼"] == "是":
        try:
            sport_situation = tree.xpath('//input[@name="EHRDETAILS.exCycle" and @checked="checked"]')[0]
            dict_group_5["锻炼情况"] = sport_situation.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["锻炼情况"] = "无"
        try:
            sport_time = tree.xpath('//input[@name="EHRDETAILS.exTime" and @checked="checked"]')[0]
            dict_group_5["每次锻炼时间"] = sport_time.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["每次锻炼时间"] = "无"
        try:
            sport_type_list = ["有氧运动（慢跑、气功、极拳、跳舞、散步、游泳、登山等）","无氧运动（速跑、篮球、排球、足球等剧烈运动）","其他"]
            checked_inputs = tree.xpath('//input[@name="EHRDETAILS.exType" and @checked]/@value')[0]
            dict_group_5["锻炼类型"] = sport_type_list[int(checked_inputs)-1]
        except:
            dict_group_5["锻炼类型"] = "无"


    elif dict_group_5["是否锻炼"] == "否":
        try:
            dict_group_5["锻炼情况"] = None
        except:
            dict_group_5["锻炼情况"] = "无"
        try:

            dict_group_5["每次锻炼时间"] = None
        except:
            dict_group_5["每次锻炼时间"] = "无"
        try:
            dict_group_5["锻炼类型"] = None
        except:
            dict_group_5["锻炼类型"] = "无"
    elif dict_group_5["是否锻炼"] == "无规律":
        try:
            dict_group_5["锻炼情况"] = None
        except:
            dict_group_5["锻炼情况"] = "无"
        try:
            dict_group_5["每次锻炼时间"] = None
        except:
            dict_group_5["每次锻炼时间"] = "无"
        try:
            dict_group_5["锻炼类型"] = None
        except:
            dict_group_5["锻炼类型"] = "无"
    else:
        try:
            sport_situation = tree.xpath('//input[@name="EHRDETAILS.exCycle" and @checked="checked"]')[0]
            dict_group_5["锻炼情况"] = sport_situation.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["锻炼情况"] = "无"
        try:
            sport_time = tree.xpath('//input[@name="EHRDETAILS.exTime" and @checked="checked"]')[0]
            dict_group_5["每次锻炼时间"] = sport_time.xpath('following-sibling::span/label/text()')[0]
        except:
            dict_group_5["每次锻炼时间"] = "无"
        try:
            sport_type_list = ["有氧运动（慢跑、气功、极拳、跳舞、散步、游泳、登山等）","无氧运动（速跑、篮球、排球、足球等剧烈运动）","其他"]
            checked_inputs = tree.xpath('//input[@name="EHRDETAILS.exType" and @checked]/@value')[0]
            dict_group_5["锻炼类型"] = sport_type_list[int(checked_inputs)-1]
        except:
            dict_group_5["锻炼类型"] = "无"

    # 饮食习惯
    food_habit_list = []
    food_habits = tree.xpath('//input[@name="EHRDETAILS.fhType" and @checked="checked"]')
    for i in food_habits:
        yinshi_type = i.xpath('following-sibling::span/label/text()')[0]
        food_habit_list.append(yinshi_type)
    dict_group_5["饮食习惯"] = '，'.join(food_habit_list)
    if dict_group_5["饮食习惯"] == "":
        dict_group_5["饮食习惯"] = "无"
    try:
        food_habits = tree.xpath('//input[@id="EHRDETAILS.fhAmount"]/@value')[0]
        dict_group_5["饮食量(主食量)"] = food_habits
        if food_habits == "":
            dict_group_5["饮食量(主食量)"] = None
    except:
        dict_group_5["饮食量(主食量)"] = None

    # 睡眠
    try:
        sleep_time = tree.xpath('//input[@name="EHRDETAILS.slTime" and @checked="checked"]')[0]
        dict_group_5["睡眠时间"] = sleep_time.xpath('following-sibling::span/label/text()')[0]
    except:
        dict_group_5["睡眠时间"] = None

    sleep_habit_list = []
    sleep_habits = tree.xpath('//input[@name="EHRDETAILS.slSituation" and @checked="checked"]')
    for i in sleep_habits:
        shuimianqingkuang = i.xpath('following-sibling::span/label/text()')[0]
        sleep_habit_list.append(shuimianqingkuang)
    dict_group_5["睡眠情况"] = '|'.join(sleep_habit_list)
    if "其他" in dict_group_5["睡眠情况"]:
        sleep_qita = tree.xpath('//input[@name="EHRDETAILS.slDescription"]/@value')[0]
        sleep_habit_list.append(sleep_qita)
        dict_group_5["睡眠情况"] = '|'.join(sleep_habit_list)
    if dict_group_5["睡眠情况"] == "":
        dict_group_5["睡眠情况"] = None
    try:
        sleep_habits_other = tree.xpath('//input[@id="EHRDETAILS.otherHabit"]/@value')[0]
        dict_group_5["其它习惯"] = sleep_habits_other
        if sleep_habits_other == "":
            dict_group_5["其它习惯"] = None
    except:
        dict_group_5["其它习惯"] = None
    print("问题不在5")
    return dict_group_5